package com.example.bookkeepingelf.business.database.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.example.bookkeepingelf.business.database.entity.AccountBook;
import java.util.List;

@Dao
public interface AccountBookDao {


    @Query("SELECT * FROM account_book")
    List<AccountBook> getAll();

    @Query("SELECT * FROM account_book order by CASE WHEN is_main THEN 0 ELSE 1 END, update_time desc")
    List<AccountBook> getAllOrderByUpdateTime();

    @Query("SELECT * FROM account_book WHERE account_book_name = :accountBookName")
    AccountBook getAccountBookByName(String  accountBookName);

    @Query("SELECT * FROM account_book WHERE is_main = 1")
    AccountBook getMainAccountBook();

    @Query("SELECT * FROM account_book WHERE id = :accountBookId")
    AccountBook getAccountBookById(int accountBookId);

    @Insert
    void insert(AccountBook accountBook);

    @Update
    void update(AccountBook accountBook);

    @Delete
    void delete(AccountBook accountBook);

    @Query("DELETE FROM account_book")
    void deleteAll();
}
